// app/extend/context.js
module.exports = {
  // 成功提示
  apiSuccess(data = "", msg = "ok", code = 200) {

    this.body = { msg, data, code: code };


  },
  // 失败提示
  apiFail(data = "", msg = "fail", code = 400) {
    this.body = { msg, data, code: code };
    this.status = code;
  },
  checkToken(token) {
    return this.app.jwt.verify(token, this.app.config.jwt.secret);
  },
  genID(length) {
    return Number(Math.random().toString().substr(3, length) + Date.now()).toString(36);
  },
  ismobile(ctx) {
    let userAgent = this.request.header['user-agent'].toLowerCase();
    let pat_phone = /ipad|iphone os|midp|rv:1.2.3.4|ucweb|android|windows ce|windows mobile/;
    return pat_phone.test(userAgent);

  }
};